package com.cskaoyan.controller.wx.zjh;

import com.cskaoyan.mapper.MarketAddressMapper;
import com.cskaoyan.module.bean.BaseRespVo;
import com.cskaoyan.module.pojo.MarketAddress;
import com.cskaoyan.module.pojo.MarketAdmin;
import com.cskaoyan.module.pojo.MarketUser;
import com.cskaoyan.service.wx.zjh.AddressService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.yaml.snakeyaml.events.Event;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Description:
 * @Author: 周佳豪
 * @Date: 2022/04/10/21:51
 */
@RestController
@RequestMapping("wx")
public class AddressController {

    @Autowired
    AddressService addressService;

    @GetMapping("address/list")
    public BaseRespVo getAddressList() {

        Subject subject = SecurityUtils.getSubject();
        MarketUser marketUser = (MarketUser) subject.getPrincipals().getPrimaryPrincipal();


        Integer id = marketUser.getId();
        BaseRespVo baseRespVo = addressService.selectAddress(id);
        return baseRespVo;
    }


    @GetMapping("address/detail")
    public BaseRespVo addressDetail(Integer id) {
        BaseRespVo baseRespVo = addressService.detailAddress(id);
        return baseRespVo;
    }

    @PostMapping("address/save")
    public BaseRespVo addressSave(@RequestBody MarketAddress address) {

        Subject subject = SecurityUtils.getSubject();
        MarketUser marketUser = (MarketUser) subject.getPrincipals().getPrimaryPrincipal();
        address.setUpdateTime(new Date());

        address.setUserId(marketUser.getId());
        BaseRespVo baseRespVo = addressService.saveAddress(address);
        return baseRespVo;
    }

    @PostMapping("address/delete")
    public BaseRespVo addressDelete(@RequestBody Map map) {
        Integer id = (Integer) map.get("id");
        BaseRespVo baseRespVo = addressService.deleteAddress(id);
        return baseRespVo;
    }



}
